package com.yindian.cos.easy.security.authentication.token;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 刷新token后的回调处理
 *
 * @author zhangchuanhao
 * @create 2018/11/23
 */
public interface RefreshTokenNotify {

    /**
     * 回调方法，默认直接输出token
     *
     * @param request
     * @param response
     * @param token
     */
    default void notify(HttpServletRequest request, HttpServletResponse response, Token token) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        response.getWriter().print(objectMapper.writeValueAsString(token));
    }
}
